<?php

/**
 * @name ErrorController
 * @desc 错误控制器, 在发生未捕获的异常时刻被调用
 */
class ErrorController extends Yaf_Controller_Abstract
{
    public function errorAction($exception)
    {
        $this->getView()->assign("exception", $exception);
        debug($exception->getMessage());

        /*Yaf has a few different types of errors*/
        switch ($exception->getCode()):
            case YAF_ERR_NOTFOUND_MODULE:
            case YAF_ERR_NOTFOUND_CONTROLLER:
            case YAF_ERR_NOTFOUND_ACTION:
            case YAF_ERR_NOTFOUND_VIEW:
                return $this->_pageNotFound();
            default:
                return $this->_unknownError();
        endswitch;
    }

    private function _pageNotFound()
    {
        $this->getResponse()->setHeader('HTTP/1.0 404 Not Found', true);
        $this->_view->error = 'Page was not found';
    }

    private function _unknownError()
    {
        $this->getResponse()->setHeader('HTTP/1.0 500 Internal Server Error', true);
        $this->_view->error = 'Application Error';
    }

}
